﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		/***
		**异步加载器
		***/
		var loader = {
			enable: true,
			pageIndex: 1,
			skip: 0,
			show: function (data, status) {
				eval(data);
				window.append(products);
				//this.sleep();
			},

			sleep: function () {
				_this = this;
				this.enable = false,
			setTimeout(function () { _this.enable = true; }, 2000);
			},

			loading: function (_url, parameter) {
				var _this = this;
				$.ajax({ type: "get", dataType: "json", data: parameter, url: _url,

					/*ajax调用之前*/
					beforeSend: function (XMLHttpRequest) {
						_this.beforeSend(XMLHttpRequest);
					},

					/**ajax调用成功之后**/
					success: function (data, textStatus) {
						_this.show(data, textStatus);
					},

					/*发生错误的处理*/
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						_this.showError(XMLHttpRequest, textStatus, errorThrown);
						//请求出错处理
					}
				});
			},

			/*加载之前可以抛出一朵菊花*/
			beforeSend: function () {
				/*空接口*/
			},
			showError: function (XMLHttpRequest, textStatus, errorThrown) {
				alert(textStatus || errorThrown);
			}
		};
		loader.show = function (data) {
			alert(data.length);
		};

		function myfunction() {
			loader.loading("Products/Loader.aspx?r="+Math.random());
		}
	</script>
</head>
<body>
	<button onclick="myfunction();">
		点我</button>
</body>
</html>
